package ecstore.client.customWidgets;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.VerticalPanel;

import ecstore.client.dataOperation.ItemInfo;

public class ItemInfoPopup extends Composite {
	// Create the popup dialog box
	final DialogBox dialogBox = new DialogBox();
	
	final Button closeButton = new Button("Close");
	final Image itemImage = new Image();

	VerticalPanel dialogVPanel = new VerticalPanel();

	public ItemInfoPopup(){
		dialogVPanel.setSize("376px", "337px");
		
		dialogBox.setText("Item description");
		dialogBox.setAnimationEnabled(true);
		dialogBox.setWidget(dialogVPanel);
		
		// We can set the id of a widget by accessing its Element
		closeButton.getElement().setId("closeButton");
		
		dialogVPanel.addStyleName("dialogVPanel");
		dialogVPanel.add(new HTML("<b>Item image</b>"));
		dialogVPanel.add(itemImage);

		dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);

		dialogVPanel.add(closeButton);
		closeButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				dialogBox.hide();
			}
		});
		
		// Note: do not initialize popup dialog, they are not widgets
//		initWidget(dialogBox);
		dialogBox.center();
	}
	
	public ItemInfoPopup(ItemInfo itemInfo){
		dialogVPanel.setSize("376px", "337px");
		
		dialogBox.setText(itemInfo.getName() + " " + itemInfo.getSize());
		dialogBox.setAnimationEnabled(true);
		dialogBox.setWidget(dialogVPanel);
		
		// We can set the id of a widget by accessing its Element
		closeButton.getElement().setId("closeButton");
		
		dialogVPanel.addStyleName("dialogVPanel");
		dialogVPanel.add(new HTML("<b>Details</b>"));
		itemImage.setUrl(itemInfo.getImage());
		dialogVPanel.add(itemImage);

		dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);

		dialogVPanel.add(closeButton);
		closeButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				dialogBox.removeFromParent();
//				dialogBox.hide();
			}
		});
		
		// Note: do not initialize popup dialog, they are not widgets
//		initWidget(dialogBox);
		dialogBox.center();
	}
	
	
	
	public void setImage(String imageURL){
		itemImage.setUrl(imageURL);
	}
	
	public void setText(String text){
		dialogBox.setText(text);
	}

}
